package com.example.children.Service;

import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.example.children.DTO.AttendanceTeacherDTO;
import com.example.children.DTO.StudentClassDTO;
import com.example.children.FileService.AttendanceInterface;
import com.example.children.Mapper.AttendanceMapper;
import com.example.children.Model.Attendance;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.Date;
import java.util.List;

@Service  //考勤
public class AttendanceService extends ServiceImpl<AttendanceMapper, Attendance> implements AttendanceInterface {

    @Autowired
    private AttendanceMapper attendanceMapper;


    //保存出勤记录
    public boolean addAttendance(Attendance attendance) {
        attendanceMapper.insert(attendance);
        return true;
    }

    //根据id提取出勤记录
    public List<Attendance> listToStudentIds(String studentId) {
        return attendanceMapper.selectByStudentId(studentId);
    }



    //根据日期查询出勤
    public List<Attendance> selectByDateSend(Attendance attendance) {
        return attendanceMapper.selectByDateSend(attendance);
    }

    //根据日期查询出勤 admin
    public List<AttendanceTeacherDTO> AdminselectByDateSend(AttendanceTeacherDTO attendance) {
        return attendanceMapper.AdminSelectByDateSend(attendance);
    }

    //查询所有出勤记录
        public Page<AttendanceTeacherDTO> GetAllAttendance(int pageNo, int pageSize) {
            // 计算分页的偏移量
            int offset = (pageNo - 1) * pageSize;

            // 获取当前页的数据
            List<AttendanceTeacherDTO> records = attendanceMapper.GetAllAttendanceTeacherDTO(offset, pageSize);
            // 获取总记录数
            int total = attendanceMapper.countTotalRecords();
            // 构造并返回分页对象
            Page<AttendanceTeacherDTO> page = new Page<>();
            page.setTotal(total);
            page.setSize(pageSize);
            page.setCurrent(pageNo);
            page.setRecords(records);

            return page;
    }


}
